package com.bawei.rk_01.cartgory

import androidx.lifecycle.viewModelScope
import com.bawei.base.utils.SingLiveData
import com.bawei.base.utils.bean.CategoryEntity
import com.bawei.base.utils.bean.GoodEnttiy
import com.bawei.base.utils.bean.Res
import com.bawei.base.utils.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CategoryViewModel : BaseViewModel() {

    //分类
    val categorysuccess = SingLiveData<Res<CategoryEntity>>()
    val categoryfail = SingLiveData<String>()
    fun category(){
        viewModelScope.launch {
            try {
                categorysuccess.postValue(apiService.category())
            }catch (e:Exception){
                categoryfail.postValue(e.message.toString())
            }
        }
    }

    val goodssuccess = SingLiveData<Res<GoodEnttiy>>()
    val goodsfail = SingLiveData<String>()

    fun goods(cid:Int,
              keyword:String,
              limit:Int,
              news:Boolean,
              page:Int,
              priceOrder:String,
              salesOrder:String){
        viewModelScope.launch {
            try {
                goodssuccess.postValue(apiService.searchGoods(cid,keyword,limit,news,page,priceOrder,salesOrder))
            }catch (e:Exception){
                goodsfail.postValue(e.message.toString())
            }
        }
    }

}